﻿using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using WMSUIMVC.Aubit.Sales;
using WMSUIMVC.DTO.Allocate;
using WMSUIMVC.DTO.Carrier;
using WMSUIMVC.DTO.Injure;
using WMSUIMVC.DTO.Refund;
using XuanKeZz.Application.HTTP;

namespace WMSUIMVC.Controllers
{
    /// <summary>
    /// 调拨单
    /// </summary>
    public class AllocateController : Controller
    {
        private readonly IConfiguration configuration;

        public AllocateController(IConfiguration configuration)
        {
            this.configuration = configuration;
        }
        //调拨单显示
        public IActionResult Allocate()
        {
            return View();
        }
        /// <summary>
        /// 显示调拨列表
        /// </summary>
        /// <returns></returns>
        public async Task<IActionResult> GetAllocate(GetAllocateDto obj)
        {
            HttpClientWrapper client = new HttpClientWrapper(obj.Token);
            string url = configuration["Url"]+ "ckd/api/Allocate/GetAllocateList?pageIndex="+obj.pageIndex+"&PageSize="+obj.PageSize+"&StartDate="+obj.StartDate+"&EndDate="+obj.EndDate + "&AllocateState=" + obj.AllocateState + "&AllocateId=" + obj.AllocateId;
            var res = await client.GetAsync(url);
            return Json(res);
        }

       

        /// <summary>
        /// 删除销售列表
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public async Task<IActionResult> DelAllocate(DelAllocateDto obj)
        {
            HttpClientWrapper client = new HttpClientWrapper(obj.Token);
            string url = configuration["Url"] + "ckx/api/Allocate/DelEnterStorage";
            //转成集合
            var list = "{\"allocateId\":" + JsonConvert.SerializeObject(obj.AllocateId) + "}";
            //将集合转成json
            var res = await client.PutAsync(url, list);
            return Json(res);
        }


        //调拨单添加
        public IActionResult AddAllocate()
        {
            return View();
        }


        /// <summary>
        /// 调拨单添加
        /// </summary>
        /// <returns></returns>
        public async Task<IActionResult> AddAllocateList(AddAllocateDto obj)
        {
            HttpClientWrapper client = new HttpClientWrapper(obj.Token);
            string url = configuration["Url"] + "ckx/api/Allocate/AddEnterStorage";
            string list = JsonConvert.SerializeObject(obj);
            string res = await client.PostAsync(url, list);
            return Json(res);
        }


        /// <summary>
        /// 显示查看详情调拨列表
        /// </summary>
        /// <returns></returns>
        public async Task<IActionResult> GetInquireAllocate(GetInquireAllocateDto obj)
        {
            HttpClientWrapper client = new HttpClientWrapper(obj.Token);
            string url = configuration["Url"] + "ckd/api/Allocate/GetAllocateInquireList?AllocateCode=" + obj.AllocateCode;
            var res = await client.GetAsync(url);
            return Json(res);
        }

        //调拨单修改
        public IActionResult UpdAllocate()
        {
            return View();
        }

        /// <summary>
        /// 调拨单修改
        /// </summary>
        /// <returns></returns>
        public async Task<IActionResult> UpdAllocateList(AddAllocateDto obj)
        {
            HttpClientWrapper client = new HttpClientWrapper(obj.Token);
            string url = configuration["Url"] + "ckx/api/Allocate/UpdEnterStorage";
            string list = JsonConvert.SerializeObject(obj);
            string res = await client.PostAsync(url, list);
            return Json(res);
        }
        /// <summary>
        /// 调拨单审批修改修改
        /// </summary>
        /// <returns></returns>
        public async Task<IActionResult> UpdAllocateStateList(AddAllocateStateDto obj)
        {
            HttpClientWrapper client = new HttpClientWrapper(obj.Token);
            string url = configuration["Url"] + "ckx/api/Allocate/UpdEnterSatetStorage";
            string list = JsonConvert.SerializeObject(obj);
            string res = await client.PostAsync(url, list);
            return Json(res);
        }
    }
}
